/*
 *  AudioPlayer.h
 *  SoundController0002
 *
 *  Created by jiro on 10/07/03.
 *  Copyright 2010 jiro music. All rights reserved.
 *
 */

#pragma once

#include <AudioUnit/AudioUnit.h>
#include "AudioUnitPlayer.h"
#include <vector>
#include <string>

#include <CoreAudio/CoreAudio.h>
#include <CoreServices/CoreServices.h>
#include <iostream>

namespace sc 
{
	class AudioPlayer : public AudioUnitPlayer
	{
	private:

		std::vector< std::vector< float >* > audioDataByChannel;

		std::vector< std::vector< float >::const_iterator > audiodDataIters;
		
		int playingIndex;
		
		int playingIndexMax;

	public:

		AudioPlayer();

		void LoadAudioData( const std::vector< std::vector< float >* >& audioDataByChannel );

		void Play( double time );

		bool IsPlaying() const;

		void Skip( double time );
		
		void Pause();

		void Stop();

	protected:
	
		static OSStatus RenderCallback( 
			void* inRefCon,
			AudioUnitRenderActionFlags* ioActionFlag,
			const AudioTimeStamp* inTimeStamp,
			UInt32 inBusNumber,
			UInt32 inNumberFrames,
			AudioBufferList* ioData );

	private:

		int GetIndexMax() const;

	};

}
